unit uFactory;

interface

uses
  uBehaviorTree;

type
  TBevNodeFactory = class
    private
      class procedure oCreateNodeCommon(_o_Me, _o_Parent: TBevNode; const _debugName: PChar);
      
    public
      class function oCreateParallelNode(_o_Parent:TBevNode;  _e_Condition: E_ParallelFinishCondition; const  _debugName: PChar): TBevNode;
      class function oCreatePrioritySelectorNode(_o_Parent:TBevNode; const  _debugName: PChar): TBevNode;
      class function oCreateNonePrioritySelectorNode(_o_Parent:TBevNode; _debugName: PChar): TBevNode;
      class function oCreateSequenceNode(_o_Parent:TBevNode; const _debugName: PChar): TBevNode;
      class function oCreateLoopNode(_o_Parent:TBevNode; const _debugName: PChar;  _i_LoopCount: Integer): TBevNode;
      class function oCreateTeminalNode(_o_Parent:TBevNode; const _debugName: PChar): TBevNode;
  end;

implementation

{ TBevNodeFactory }

class function TBevNodeFactory.oCreateLoopNode(_o_Parent: TBevNode;
  const _debugName: PChar; _i_LoopCount: Integer): TBevNode;
begin
  Result := TBevNodeLoop.Create(_o_Parent, nil, _i_LoopCount);
  oCreateNodeCommon(Result, _o_Parent, _debugName);
end;

class procedure TBevNodeFactory.oCreateNodeCommon(_o_Me,
  _o_Parent: TBevNode; const _debugName: PChar);
begin
  if Assigned(_o_Parent) then
    _o_Parent.AddChildNode(_o_Me);
  _o_Me.SetDebugName(_debugName);
end;

class function TBevNodeFactory.oCreateNonePrioritySelectorNode(
  _o_Parent: TBevNode; _debugName: PChar): TBevNode;
begin
  Result := TBevNodeNonePrioritySelector.Create(_o_Parent);
  oCreateNodeCommon(Result, _o_Parent, _debugName);
end;

class function TBevNodeFactory.oCreateParallelNode(_o_Parent: TBevNode;
  _e_Condition: E_ParallelFinishCondition;
  const _debugName: PChar): TBevNode;
begin
  Result := TBevNodeParallel.Create(_o_Parent);
  Result.SetFinishCondition(_e_Condition);
  oCreateNodeCommon(Result, _o_Parent, _debugName);
end;

class function TBevNodeFactory.oCreatePrioritySelectorNode(
  _o_Parent: TBevNode; const _debugName: PChar): TBevNode;
begin
  Result := TBevNodePrioritySelector.Create(_o_Parent);
  oCreateNodeCommon(Result, _o_Parent, _debugName);
end;

class function TBevNodeFactory.oCreateSequenceNode(_o_Parent: TBevNode;
  const _debugName: PChar): TBevNode;
begin
  Result := TBevNodeSequence.Create(_o_Parent);
  oCreateNodeCommon(Result, _o_Parent, _debugName);
end;

class function TBevNodeFactory.oCreateTeminalNode(_o_Parent: TBevNode;
  const _debugName: PChar): TBevNode;
begin
  Result := TBevNodeTerminal.Create(_o_Parent);
  oCreateNodeCommon(Result, _o_Parent, _debugName);
end;

end.
